package 回文串;

public class test2 {
    public String longestPalindrome(String s){
        int n = s.length();
        boolean[][] dp = new boolean[n][n];
        int result = 0;//用来记录起始点
        int max = Integer.MIN_VALUE;// 长度
        for (int i = n-1; i >= 0; i--) {
            for (int j = i; j < n; j++) {
                if(s.charAt(i)==s.charAt(j))
                    dp[i][j] = i+1<j?dp[i+1][j-1]:true;
                else dp[i][j] = false;
                if(dp[i][j]&&(j-i+1)>max){
                    max = j-i+1;
                    result = i;
                }
            }
        }
        return s.substring(result,result+max);
    }
}
